// Framework: None
// Technology stack: None

#include <iostream>
#include <vector>
#include <cmath>

bool isPrime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int nextPrime(int n) {
    if (n < 2) {
        return 2;
    }
    while (!isPrime(n)) {
        n++;
    }
    return n;
}

int previousPrime(int n) {
    if (n < 2) {
        return 2;
    }
    while (!isPrime(n)) {
        n--;
    }
    return n;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> words;
    std::string word;
    for (char c : input) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    words.push_back(word);

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int n = 0;
    for (std::string word : words) {
        if (word == "zero") {
            n = n * 10;
        } else if (word == "one") {
            n = n * 10 + 1;
        } else if (word == "two") {
            n = n * 10 + 2;
        } else if (word == "three") {
            n = n * 10 + 3;
        } else if (word == "four") {
            n = n * 10 + 4;
        } else if (word == "five") {
            n = n * 10 + 5;
        } else if (word == "six") {
            n = n * 10 + 6;
        } else if (word == "seven") {
            n = n * 10 + 7;
        } else if (word == "eight") {
            n = n * 10 + 8;
        } else if (word == "nine") {
            n = n * 10 + 9;
        } else {
            std::cout << "Wrong input" << std::endl;
            return 0;
        }
    }

    std::vector<int> c;
    c.push_back(isPrime(n));
    c.push_back(n);
    c.push_back(previousPrime(n));
    if (c[0] - c[1] < c[1] - c[2]) {
        std::cout << c[0] << std::endl;
    } else {
        std::cout << c[2] << std::endl;
    }

    return 0;
}